home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / ViewerOptBtnSample / Source / Menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  2.9 KB  |  190 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        MENUS             */
  3. /****************************/
  4.  
  5.  
  6. /***************/
  7. /* EXTERNALS   */
  8. /***************/
  9. #include <Dialogs.h>
  10. #include <Menus.h>
  11. #include <ToolUtils.h>
  12. #include <Devices.h>
  13.  
  14. #include "myglobals.h"
  15. #include "mymenus.h"
  16. #include "misc.h"
  17. #include "process.h"
  18.  
  19.  
  20. /******************/
  21. /*  PROTOTYPES    */
  22. /******************/
  23.  
  24. static void HandleSpecialMenuChoice(short theItem);
  25.  
  26.  
  27. /****************************/
  28. /*    CONSTANTS             */
  29. /****************************/
  30.  
  31.                                     // MENU BAR ITEMS //
  32. #define    NOT_A_NORMAL_MENU    -1
  33. #define    APPLE_MENU_ID        400
  34. #define    FILE_MENU_ID        401
  35. #define EDIT_MENU_ID        402
  36.  
  37.  
  38.                                     // EDIT MENU ITEMS //
  39.                                     
  40. enum
  41. {
  42.     UNDO_ITEM    =    1,
  43.     CUT_ITEM    =    3,
  44.     COPY_ITEM    =    4,    
  45.     PASTE_ITEM    =    5,
  46.     CLEAR_ITEM    =    6
  47. };
  48.  
  49.                                     // FILE MENU ITEMS //
  50. enum
  51. {
  52.     SAVE_ITEM    = 1,
  53.     QUIT_ITEM    = 2
  54. };
  55.  
  56.  
  57.                                     // APPLE MENU ITEMS //
  58. enum                                    
  59. {                                    
  60.     ABOUT_ITEM = 1,
  61.     HELP_ITEM = 2
  62. };
  63.  
  64.  
  65.  
  66. /**********************/
  67. /*     VARIABLES      */
  68. /**********************/
  69.  
  70. MenuHandle    gAppleMenu;
  71.  
  72.  
  73. /******************/
  74. /* INIT MENU BAR  */
  75. /******************/
  76.  
  77. void InitMenuBar(void)
  78. {
  79. Handle    myMenuBar;
  80.         
  81.                     /* ALLOCATE MAIN MENU BAR */
  82.     
  83.     if ((myMenuBar    =    GetNewMBar(400)) == nil)
  84.             DoFatalAlert("\pWhered the menu bar go?!");;
  85.     SetMenuBar(myMenuBar);
  86.     
  87.                     /* SET APPLE MENU */
  88.  
  89.     if ((gAppleMenu    =    GetMenuHandle(400)) == nil)
  90.             DoFatalAlert("\pGetMHandle failed!");
  91.     AppendResMenu (gAppleMenu, 'DRVR');                        // APPEND DESK ACCESSORIES
  92.     
  93.     DrawMenuBar();
  94. }
  95.  
  96.  
  97. /***************************/
  98. /* HANDLE MENU BAR CHOICE  */
  99. /***************************/
  100.  
  101. void HandleMenuChoice(long menuChoice)
  102. {
  103. short    theMenu;
  104. short    theItem;
  105.         
  106.     if    (menuChoice != 0)
  107.     {
  108.         theMenu    =    HiWord(menuChoice);
  109.         theItem    =    LoWord(menuChoice);
  110.         switch    (theMenu)
  111.         {
  112.             case    APPLE_MENU_ID:
  113.                     HandleAppleChoice(theItem);
  114.                     break;
  115.                     
  116.             case    FILE_MENU_ID:
  117.                     HandleFileChoice(theItem);
  118.                     break;
  119.                     
  120.             case    EDIT_MENU_ID:
  121.                     HandleEditChoice(theItem);
  122.                     break;
  123.                     
  124.                     
  125.         }
  126.         HiliteMenu(0);
  127.     }
  128. }
  129.  
  130.  
  131. /*****************************/
  132. /* HANDLE APPLE MENU CHOICE  */
  133. /*****************************/
  134.  
  135. void HandleAppleChoice(short theItem)
  136. {
  137. Str255    accName;
  138. short        accNumber;
  139.         
  140.     switch    (theItem)
  141.     {
  142.         case    ABOUT_ITEM:
  143.         
  144.                 Alert(402,nil);
  145.                 break;
  146.         case    HELP_ITEM:
  147.                 Alert(128,nil);
  148.                 break;
  149.             
  150.         default:
  151.                 GetMenuItemText(gAppleMenu,theItem,accName);
  152.                 accNumber    =    OpenDeskAcc(accName);
  153.                 break;
  154.     }
  155. }
  156.  
  157. /****************************/
  158. /* HANDLE FILE MENU CHOICE  */
  159. /****************************/
  160.  
  161. void HandleFileChoice(short theItem)
  162. {
  163.     switch(theItem)
  164.     {
  165.         case    SAVE_ITEM:
  166.                 SaveViewerPICT();
  167.                 break;
  168.                 
  169.         case    QUIT_ITEM:
  170.                 CleanQuit();
  171.     }
  172. }
  173.  
  174.  
  175. /****************************/
  176. /* HANDLE EDIT MENU CHOICE  */
  177. /****************************/
  178.  
  179. void HandleEditChoice(short theItem)
  180. {
  181.     SystemEdit(theItem-1);
  182.         
  183.     switch(theItem)
  184.     {
  185.     }
  186. }
  187.  
  188.  
  189.  
  190.